document.addEventListener("DOMContentLoaded", function () {
  const formatBtn = document.getElementById("formatBtn");
  const copyBtn = document.getElementById('copyBtn');
  const jsonInput = document.getElementById("jsonInput");

  formatBtn.addEventListener("click", function () {
    const json = jsonInput.value.trim();
    if (json) {
      chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        chrome.tabs.sendMessage(
          tabs[0].id,
          { action: "formatJson", json },
          function (response) {
            if (response.error) {
              output.textContent = "Error: " + response.error;
            } else {
              output.textContent = response.formattedJson;
            }
          }
        );
      });
    }
  });
});
